#include <algorithm>
#include <cstdio>

typedef long long ll;
const int maxN = 20, mod = 998244353;
int n, m, q, N, U;
int pos[maxN], deg[maxN], a[maxN][maxN], x[maxN], inv[maxN], sta[maxN],
    f[1 << maxN][maxN], id[maxN];

inline ll qpow(ll base, int exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) res = res * base % mod;
    exp >>= 1;
    base = base * base % mod;
  }
  return res;
}

inline int sub(int i, int j) { return i -= j, i < 0 ? i + mod : i; }

inline int plus(int i, int j) { return i += j, i < mod ? i : i - mod; }

inline void Gauss(int row) {
  for (int i = 1, maxi; i <= row; ++i) {
    maxi = i;
    for (int j = i; j <= row; ++j) {
      if (std::abs(a[maxi][i]) < std::abs(a[j][i])) maxi = j;
    }
    if (maxi != i) std::swap(a[maxi], a[i]);
    ll tmp = qpow(a[i][i], mod - 2);
    for (int j = 1, rate; j <= row; ++j)
      if (i != j) {
        rate = a[j][i] * tmp % mod;
        for (int k = i; k <= row + 1; ++k)
          a[j][k] = sub(a[j][k], 1ll * rate * a[i][k] % mod);
      }
  }
  for (int i = 1; i <= row; ++i) {
    x[i] = a[i][row + 1] * qpow(a[i][i], mod - 2) % mod;
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P4321 随机漫游.in", "r", stdin);
  freopen("P4321 随机漫游.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &N, &m);
  U = (1 << N) - 1, inv[1] = 1;
  for (int i = 2; i <= N; ++i) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;

  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    ++deg[u], ++deg[v];
    sta[u] |= 1 << (v - 1);
    sta[v] |= 1 << (u - 1);
  }

  for (int status = U - 1; status; --status) {
    int cnt = 0, tmp, p;
    for (int i = 1; i <= N; ++i)
      if (status & (1 << (i - 1))) id[pos[i] = ++cnt] = i;
    for (int i = 1; i <= cnt; ++i) {
      for (int j = 1; j <= cnt; ++j) a[i][j] = 0;
      x[i] = 0;
    }
    for (int i = 1; i <= N; ++i)
      if (status & (1 << (i - 1))) {
        tmp = inv[deg[i]], p = pos[i];
        a[p][p] = 1, a[p][cnt + 1] = 1;
        for (int j = 1; j <= N; ++j)
          if (sta[i] & (1 << (j - 1))) {
            if (status & (1 << (j - 1)))
              a[p][pos[j]] = sub(a[p][pos[j]], tmp);
            else
              a[p][cnt + 1] =
                  plus(a[p][cnt + 1], 1ll * tmp * f[status | (1 << (j - 1))][j] % mod);
          }
      }
    Gauss(cnt);
    for (int i = 1; i <= cnt; ++i) {
      f[status][id[i]] = x[i];
    }
  }
  scanf("%d", &q);
  for (int i = 1, tmp, status = 0; i <= q; ++i, status = 0) {
    scanf("%d", &n);
    while (n--) scanf("%d", &tmp), status |= 1 << (tmp - 1);
    scanf("%d", &tmp);
    printf("%d\n", f[(1 << (tmp - 1)) | (U ^ status)][tmp]);
  }
  return 0;
}